package com.isoft.student.controller;

import com.isoft.student.eo.LogonlogEOPage;
import com.isoft.student.model.Logonlog;
import com.isoft.student.service.LogonlogService;
import com.isoft.student.tool.ResponseMessage;
import com.isoft.student.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对外提供数据接口
 */
@Api(tags = "logonlog")
@RestController
public class LogonlogController {

    @Autowired
    private LogonlogService logonlogService;

    @ApiOperation(value = "登录日志添加方法")
    @RequestMapping(value = "/addLogonlog",method = RequestMethod.GET)
    public ResponseMessage add(Logonlog logonlog){
        int IsAdd = 0;
        //传入数据的判断
        //1.实体对象不能为空
        if (logonlog!=null){
            //2.答题提交不能为空
            if (logonlog.getLoginaddress()!=null){
                //3.添加
                IsAdd =logonlogService.AddLogonlog(logonlog);
                if (IsAdd == 1) {
                    return Result.success("保存成功");
                } else if (IsAdd == -1) {
                    return Result.error(" 角色重复不允许添加");
                } else {
                    return Result.error("保存失败");
                }
            }
        }
        return Result.error("保存失败");
    }

    @ApiOperation(value = "根据条件获取登录日志信息")
    @RequestMapping(value = "/getLogonlogWhereAll",produces = "application/json;charset=utf-8",method=RequestMethod.PUT)
    private ResponseMessage getAll(LogonlogEOPage logonlogEOPage){
        Map<String, List> map=new HashMap<>();
        List<LogonlogEOPage> listLogonlog=logonlogService.getLogonlogWhereAll(logonlogEOPage);
        map.put("list",listLogonlog);
        return Result.success("200",map);
    }
}
